<?php

/**
 * Twoir CMS系统 twCMS
 *
 * (c) cighsen02 <xiayu@959602.com>
 *
 * Create at：2024.10.14
 * Update at: 2025.08.27
*/

namespace App\View\Components;

use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;

use function is_array;

class NavigationItem extends Component
{
    /**
     * Create a new component instance.
     */
    public function __construct(
        public array|string $route,
        public string $accountType,
        public ?string $icon = null
    )
    {
        if (!is_array($this->route)) $this->route = [$this->route];
    }

    /**
     * Summary of isActive
     * 
     * @return bool
     */
    public function isActive(): bool
    {
        foreach($this->route as $route){

            if (request()->routeIs($route)) {

                return true;
            }
        }

        return false;
    }

    /**
     * Get the view / contents that represent the component.
     * 
     * @return View|Closure|string
     */
    public function render(): View|Closure|string
    {
        return view('components.navigation-item');
    }
}
